﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace SFast.Encryption
{
    public static class MD5Encryption
    {
        #region String 扩展函数  _ToMD5()   标准MD5加密
        /// <summary>
        /// 标准MD5加密
        /// </summary>
        /// <param name="Str"></param>
        /// <returns></returns>
        public static String _ToMD5(this String Str)
        {
            MD5CryptoServiceProvider hashmd5;
            hashmd5 = new MD5CryptoServiceProvider();
            return BitConverter.ToString(hashmd5.ComputeHash(Encoding.Default.GetBytes(Str))).Replace("-", "").ToLower();//asp是小写,把所有字符变小写
        }

        /// <summary>
        /// 标准MD5加密
        /// </summary>
        /// <param name="Str"></param>
        /// <param name="encoding">编码方式</param>
        /// <returns></returns>
        public static String _ToMD5(this String Str,Encoding encoding)
        {
            MD5CryptoServiceProvider hashmd5;
            hashmd5 = new MD5CryptoServiceProvider();
            return BitConverter.ToString(hashmd5.ComputeHash(encoding.GetBytes(Str))).Replace("-", "").ToLower();//asp是小写,把所有字符变小写
        }
        #endregion
    }
}
